/*
 * OPIAM Suite
 *
 * Distributable under LGPL license.
 * See terms of license at gnu.org.
 */

package opiam.admin.faare.struts.unittests;

import opiam.admin.faare.SearchResult;
import opiam.admin.faare.struts.unittests.javabeans.TestElement;

import org.apache.commons.beanutils.PropertyUtils;

import java.lang.reflect.Field;

import java.util.ArrayList;
import java.util.List;


/**
 * @author triyanto
 *
 */
public class Test
{
    /**
     * DOCUMENT ME!
     *
     * @param args DOCUMENT ME!
     */
    public static void main(String[] args)
    {
        SearchResult objSource = new SearchResult();
        List maliste = new ArrayList();
        System.out.println("class = " + objSource.getClass());

        try
        {
            //Class c = (Class) PropertyUtils.getProperty(maliste, "class");            
            List toto = (List) PropertyUtils.getProperty(objSource, "LResults");
            System.out.println("RESULT = " + toto.size());
        }
        catch (Exception e)
        {
            System.out.println(e);
        }
    }

    /**
     * DOCUMENT ME!
     *
     * @param args DOCUMENT ME!
     */
    public static void testReflection(String[] args)
    {
        TestElement toto = new TestElement();

        Field widthField;
        Integer widthValue;
        Class c = toto.getClass();

        System.out.println("class = " + c);

        try
        {
            //Field[] publicFields = c.getFields();
            Field[] publicFields = c.getDeclaredFields();

            for (int i = 0; i < publicFields.length; i++)
            {
                String fieldName = publicFields[i].getName();
                Class typeClass = publicFields[i].getType();
                String fieldType = typeClass.getName();
                System.out.println("Name: " + fieldName + ", Type: " +
                    fieldType);
            }

            widthField = c.getDeclaredField("test");

            System.out.println("widthField = " + widthField);
            widthField.setAccessible(true);
            widthField.set(toto, "maman");
        }
        catch (NoSuchFieldException e)
        {
            System.out.println(e);
        }
        catch (IllegalAccessException e)
        {
            System.out.println(e);
        }

        System.out.println("RESULT = " + toto.getTest());
    }
}
